/**
 * PropertyPlaceholderConfigurer.java
 * com.sitech.ismp.util
 *
 * Function： TODO 
 *
 *   ver     date      		author
 * ──────────────────────────────────
 *   		 Jun 28, 2010 		geutopia
 *
 * Copyright (c) 2010, TNT All Rights Reserved.
 */

package com.sitech.util;

import java.util.List;
import java.util.Properties;

import com.sitech.util.password.PasswordEncoder;

/**
 * ClassName:PropertyPlaceholderConfigurer
 * Function: TODO ADD FUNCTION
 * Reason:	 TODO ADD REASON
 *
 * @author   geutopia
 * @version  
 * @since    Ver 1.1
 * @Date	 Jun 28, 2010		1:29:25 PM
 *
 * @see 	 
 */
public class PropertyPlaceholderConfigurer extends
		org.springframework.beans.factory.config.PropertyPlaceholderConfigurer
{
	private List<String> encryptList;
	
	private PasswordEncoder passwordEncoder;

	protected void convertProperties(Properties props)
	{
		
		if (encryptList != null && passwordEncoder != null)
		{
			for (String encrypt : encryptList)
			{
				if (props.containsKey(encrypt))
				{
					String value = (String) props.get(encrypt);
					value = passwordEncoder.decode(value);
					props.setProperty(encrypt, value);
				}
			}
		}

		for(Object key: props.keySet())
		{
			if(!System.getProperties().containsKey(key))
			{
				System.setProperty((String)key, props.getProperty((String)key));
			}
		}
		
		

		
		
	}
	
	public List<String> getEncryptList()
	{
		return encryptList;
	}

	public void setEncryptList(List<String> encryptList)
	{
		this.encryptList = encryptList;
	}

	public PasswordEncoder getPasswordEncoder()
	{
		return passwordEncoder;
	}

	public void setPasswordEncoder(PasswordEncoder passwordEncoder)
	{
		this.passwordEncoder = passwordEncoder;
	}
}
